package com.io.security.security;

import com.io.utils.JwtUtils;
import io.jsonwebtoken.CompressionCodecs;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class TokenManager {
    //token有效时长
    private long tokenEcpiration =24*60*60*1000;
    //编码秘钥
    private String tokenSignKey = "ukc8BDbRigUDaY6pZFfWus2jZWLPHO";
    //1 使用jwt根据用户名生成token
    public String createToken(String username) {
        String token = JwtUtils.getJwtToken(username);
        return token;
    }
    //2 根据token字符串得到用户信息
    public String getUserInfoFromToken(String token) {

//        String userinfo = Jwts.parser().setSigningKey(tokenSignKey).parseClaimsJws(token).getBody().getSubject();
//        return userinfo;

        boolean b = JwtUtils.checkToken(token);
        boolean b1 = JwtUtils.checkToken(token);
        if (b&&b1){
            String userinfo = JwtUtils.getMemberUsernameByJwtToken(token);
            return userinfo;
        }
        return null;

    }
    //3 删除token
    public void removeToken(String token) { }
}
